home *** CD-ROM | disk | FTP | other *** search
- /*
- File: AboutBox.cpp
-
- Contains: Functions to handle the About Box display
-
- Owned by: Chris Linn
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <1> 10/4/96 CSL first checked in
- */
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include "WinStat.xh"
- #endif
-
- #ifndef _USERSRCM_
- #include "UseRsrcM.h"
- #endif
-
- #ifndef _DLGDEFS_
- #include "DdgDefs.h"
- #endif
-
- #ifndef _ODVERSNM_
- #include "ODVersnM.h"
- #endif
-
- #ifndef _PASCLSTR_
- #include "PasclStr.h"
- #endif
-
- #include <stdio.h>
-
- //
- // Types
- //
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- struct VersRsrc {
- unsigned long versionCode;
- short region;
- Str255 versionStr;
- };
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- //
- // Exports
- //
-
- extern "C" void ShowAboutBoxEntry( Environment* ev, ODWindowState* windowState );
-
- //
- // Private
- //
-
- static short GetMainDeviceDepth( ODBoolean *isColor )
- {
- GDHandle device;
- short depth;
- PixMapHandle pmap;
-
- depth = 1;
- *isColor = kODTrue;
- device = GetMainDevice();
- if (
- (TestDeviceAttribute(device, screenDevice)) &&
- (TestDeviceAttribute(device, screenActive))
- ) {
- pmap = (*device)->gdPMap;
- depth = (*pmap)->pixelSize;
- *isColor = TestDeviceAttribute(device,gdDevType);
- }
-
- return(depth);
- }
-
- static DialogPtr OpenAboutBoxDialog( )
- {
- DialogPtr aboutScreen = NULL;
- Boolean color;
- short depth = GetMainDeviceDepth(&color);
-
- short pictID = kODDlgAboutBoxDefaultPICTID;
-
- Str255 s255; s255[0]=0;
- WindowPtr ww = FrontWindow();
- if (ww)
- GetWTitle(ww, s255);
- else
- BlockMove(LMGetCurApName(), s255, 32);
-
- if (!EqualString(s255, "\pAbout OpenDoc...", TRUE, FALSE))
- {
- // Note, the above string is NEVER user visible, so there is no need
- // to worry about localizing it.
- if( !color && depth>=4 )
- pictID = kODDlgAboutBox16GrayPICTID; // Use grayscale
- else if( depth>=8 )
- pictID = kODDlgAboutBoxBestPICTID; // Use 8-bit color
- else
- pictID = kODDlgAboutBoxBWPICTID; // Use black-and-white
- }
-
- if( Get1Resource('DLOG',kODDlgAboutBoxDLOGID) )
- aboutScreen = GetNewDialog(kODDlgAboutBoxDLOGID,NULL,(WindowPtr)-1L);
- if( aboutScreen ) {
- short itemHit;
- Handle scratchHandle = kODNULL;
- Rect itemRect;
-
- GetDialogItem(aboutScreen, 1, &itemHit, &scratchHandle, &itemRect);
-
- PicHandle pictHandle = (PicHandle)Get1Resource('PICT', pictID);
-
- TEHandle te = ((DialogPeek)aboutScreen)->textH;
- (**te).just = teJustCenter;
-
- // Get the CFM version and the vers resource
- ODVersion cfmVersion = 0;
- OSErr err = ODGetOpenDocVersion( &cfmVersion );
- VersRsrc **vers = (VersRsrc**) Get1Resource('vers',2);
-
- if ( err != noErr && vers == kODNULL )
- {
- // Worst case--can't get any version info
- WARN( "Can’t find any version info!" );
- ParamText( "\p", kODNULL, kODNULL, kODNULL );
- }
- else if ( vers == kODNULL || ((**vers).versionCode >> 16) != ( cfmVersion >> 16 ))
- {
- // Couldn't get vers data, or it doesn't match the CFM version number
- // (high word only), so use the CFM version
- WARN( "CFM version does not match the vers resource!" );
-
- char versionBuf[100];
- const unsigned long kNibbleMask = 0x0000000F;
- ODUShort major = (( cfmVersion >> 28 ) & kNibbleMask ) * 10
- +(( cfmVersion >> 24 ) & kNibbleMask );
- ODUShort minor = (( cfmVersion >> 20 ) & kNibbleMask );
- ODUShort update = (( cfmVersion >> 16 ) & kNibbleMask );
- sprintf( versionBuf, update ? "%d.%d.%d" : "%d.%d",
- major, minor, update ? update : kODNULL );
- StringPtr versionStr = CToPascalString( versionBuf );
- ParamText( versionStr, kODNULL, kODNULL, kODNULL );
- }
- else
- {
- // Use the vers resource, since it contains pre-release version info
- HLock((Handle)vers);
- ParamText( (**vers).versionStr, kODNULL, kODNULL, kODNULL );
- }
-
- if ( vers != kODNULL )
- {
- ReleaseResource( (Handle)vers );
- vers = kODNULL;
- }
-
- ShowWindow(aboutScreen);
- SelectWindow(aboutScreen);
- DrawDialog(aboutScreen);
- SetPort(aboutScreen);
- if (pictHandle)
- {
- HLock((Handle)pictHandle);
- DrawPicture(pictHandle, &itemRect);
- HUnlock((Handle)pictHandle);
- ReleaseResource((Handle)pictHandle);
- }
-
- ValidRect(&aboutScreen->portRect);
- }
- return aboutScreen;
- }
-
- //
- // Public
- //
-
- void ShowAboutBoxEntry( Environment* ev, ODWindowState* windowState )
- {
- CUsingLibraryResources r;
- ODSShort itemHit;
- GrafPtr savePort; ODVolatile(savePort);
- GetPort(&savePort);
-
- windowState->DeactivateFrontWindows(ev);
- TRY
- DialogPtr aboutDlg = OpenAboutBoxDialog();
-
- ModalDialog(kODNULL /*modalFilter*/, &itemHit);
- if (aboutDlg)
- DisposeDialog(aboutDlg);
- CATCH_ALL
- windowState->ActivateFrontWindows(ev);
- SetPort(savePort);
- RERAISE;
- ENDTRY
- windowState->ActivateFrontWindows(ev);
- SetPort(savePort);
- }
-